package com.rakuten.api.mule.transformers;

import java.util.HashMap;
import java.util.Map;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.api.transport.PropertyScope;
import org.mule.transformer.AbstractMessageTransformer;


import com.rakuten.api.mule.model.FindShopInfo;

import com.rakuten.api.mule.model.shop.Shop;;


public class getShopInfoResponse extends AbstractMessageTransformer {
	@Override
	public Object transformMessage(MuleMessage message, String outputEncoding)
			throws TransformerException {

		try {
			FindShopInfo shopInfo = message.getPayload(FindShopInfo.class);
			
			Map<String, FindShopInfo> shopInfoMap = message.getProperty(
					"findShopInfoMap", PropertyScope.SESSION);
			//if object is null, instantiate it
			if (shopInfoMap == null) {
				shopInfoMap = new HashMap<String, FindShopInfo>();
			}
			//put data to Map
			String shopUrl = message.getInboundProperty("shopUrl");			
			shopInfoMap.put(shopUrl, shopInfo);
			//save to property
			message.setProperty("findShopInfoMap", shopInfoMap,
					PropertyScope.SESSION);

			return message;
		} catch (Exception ex) {
			throw new TransformerException(this, ex);
		}
	}
}



